/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.events.ActionEvent;
import view.additional.CellItem;
import view.additional.ThumbList;
import view.additional.TickerRenderer;

/**
 *
 * @author Kvest
 */
public class ParkingList extends Form implements ActionListener
{
    public static final int REGISTRATION_ID = 1;
    public static final int BACK_ID = 2;
    public static final int UPDATE_ID = 3;
    public static final int UNREGISTER_ID = 4;

    private Command registration;
    private Command back;
    private Command update;
    private Command unregister;
    
    private FormAction listener;

    private ThumbList positionsList;
    
    public ParkingList(FormAction listener)
    {
        super("Стоянки");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());
        setScrollable(false);

        addCommandListener(this);

        back= new Command("Назад", BACK_ID);
        addCommand(back);

        unregister = new Command("Снять с сектора", UNREGISTER_ID);
        addCommand(unregister);

        update = new Command("Обновить", UPDATE_ID);
        addCommand(update);

        registration = new Command("Стать", REGISTRATION_ID);
        addCommand(registration);

        //Создаем и настраиваем список
        positionsList = new ThumbList();
        positionsList.setSelectCommandText("");
        positionsList.setFixedSelection(ThumbList.FIXED_NONE_CYCLIC);
        TickerRenderer render = new TickerRenderer();
        render.getStyle().setPadding(Component.BOTTOM, 0);
        render.getStyle().setPadding(Component.TOP, 0);
        positionsList.setRenderer(render);
        positionsList.getStyle().setPadding(Component.BOTTOM, 0);
        positionsList.getStyle().setPadding(Component.TOP, 0);
        addComponent(BorderLayout.CENTER, positionsList);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public void clear()
    {
        while (positionsList.size() > 0)
        {
            positionsList.getModel().removeItem(0);
        }
    }

    public void add(CellItem position)
    {
        positionsList.getModel().addItem(position);
    }

    public CellItem getSelectedItem()
    {
        return (CellItem)positionsList.getSelectedItem();
    }
}
